#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+


[[ $CCI_SRC ]] || CCI_SRC=/c/compass-ci
[[ $LKP_SRC ]] || LKP_SRC=/c/lkp-tests
[[ $UPSTREAM_REPOS_PATH ]] || UPSTREAM_REPOS_PATH=/c/upstream-repos

. $CCI_SRC/container/defconfig.sh

start_pod
docker_rm web-backend

load_cci_defaults
[[ $SRV_HTTP_RESULT_HOST ]] || SRV_HTTP_RESULT_HOST=$(curl ip.sb)
[[ $SRV_HTTP_RESULT_PORT ]] || SRV_HTTP_RESULT_PORT=20007
[[ $ETCD_HOST ]] || ETCD_HOST=172.17.0.1
[[ $ETCD_PORT ]] || ETCD_PORT=2379
[[$lab]] || lab=z9
LAB_PATH="/c/lab-$lab"

load_service_authentication

cmd=(
	docker run
	--name web-backend
	--restart=always
	-d
	-p 10002:10002

	-e ES_PORT=9200
	-e SRV_HTTP_RESULT_HOST=$SRV_HTTP_RESULT_HOST
	-e SRV_HTTP_RESULT_PORT=$SRV_HTTP_RESULT_PORT
	-e ETCD_PORT=$ETCD_PORT
	-e ETCD_HOST=$ETCD_HOST
	-e CCI_SRC=/c/compass-ci
	-e LKP_SRC=/c/lkp-tests
	-e UPSTREAM_REPOS_PATH=/c/upstream-repos
	-e ES_USER=$ES_USER
	-e ES_PASSWORD=$ES_PASSWORD
	-e LOGGING_ES_USER=$LOGGING_ES_USER
	-e LOGGING_ES_PASSWORD=$LOGGING_ES_PASSWORD
	-e LAB=$lab
	-e OAUTH_CLIENT_ID=$OAUTH_CLIENT_ID
	-e OAUTH_CLIENT_SECRET=$OAUTH_CLIENT_SECRET
	-e OAUTH_REDIRECT_URL=$OAUTH_REDIRECT_URL
	-e JWT_SECRET=$JWT_SECRET

	-v $CCI_SRC:/c/compass-ci
	-v $LKP_SRC:/c/lkp-tests
	-v $LAB_PATH:$LAB_PATH
	-v $UPSTREAM_REPOS_PATH:/c/upstream-repos
	-v /etc/compass-ci:/etc/compass-ci:ro
	-v /etc/localtime:/etc/localtime:ro

	--log-opt mode=non-blocking
	--log-opt max-buffer-size=4m

	centos:web-backend
	/c/compass-ci/container/web-backend/web-backend
)

"${cmd[@]}"
